﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using Lm.Common.ExtensionMethods;

namespace Lm.Common.Auth.Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(Server));
            System.Threading.Thread.Sleep(1000);
            System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(Client));
            System.Console.Read();
        }

        static void Server(object obj)
        {
            var server = new Lm.Common.Net.Server("127.0.0.1", 8877);
            server.Start();
        }
        static void Client(object obj)
        {
            var client = new Lm.Common.Net.Client("127.0.0.1", 8877);
            try
            {
                var response = client.Request(new Request());
            }
            catch { } 
            try
            {
                //var response2 = client.Request(new Request());
            }
            catch { }
        }
    }
    [Serializable]
    class Request : Lm.Common.Net.IRequestMessage<Response>
    { }
    [Serializable]
    class Response : Lm.Common.Net.IResponseMessage
    {
        public string str { get; set; }
    }
    [Serializable]
    class Response2 : Lm.Common.Net.IResponseMessage
    { }
    class RequestService : Lm.Common.Net.IRequestHandler
    {
        #region IRequestHandler 成员

        public object Handle(object request)
        {
            return new Response() { str = DateTime.Now.ToString() };
        }

        #endregion
    }
}
